import request from "@/utils/request";
import {
  GetUserListApiParams,
  GetUserListApiResponse,
  UpdateUserApiParams,
  AddUserApiParams,
  GetUserRoleListApiResponse,
} from "./model/userModel";

const enum Api {
  getUserList = "/admin/acl/user",
  addUser = "/admin/acl/user/save",
  updateUser = "/admin/acl/user/update",
  removeUser = "/admin/acl/user/remove",
  getUserRoleList = "/admin/acl/user/toAssign",
  assignUserRoleList = "/admin/acl/user/doAssign",
}

export const getUserListApi = ({
  page,
  limit,
  username,
}: GetUserListApiParams) => {
  return request.get<any, GetUserListApiResponse>(
    Api.getUserList + `/${page}/${limit}`,
    {
      params: {
        username,
      },
    }
  );
};

export const addUserApi = (data: AddUserApiParams) => {
  return request.post<any, null>(Api.addUser, data);
};

export const updateUserApi = (data: UpdateUserApiParams) => {
  return request.put<any, null>(Api.updateUser, data);
};

export const removeUserApi = (id: string) => {
  return request.delete<any, null>(Api.removeUser + `/${id}`);
};

export const getUserRoleListApi = (userId: string) => {
  return request.get<any, GetUserRoleListApiResponse>(
    Api.getUserRoleList + `/${userId}`
  );
};

export const assignUserRoleListApi = (userId:string,roleId:string[]) =>{
  return request.post<any,null>(Api.assignUserRoleList,{},{
    params:{
      userId,
      roleId:roleId.join(",")
    }
  })
}
